package com.offcn.utils;

import javax.servlet.http.Part;
import java.io.File;
import java.io.IOException;
import java.util.UUID;

public class UploadUtils {

    public static String uploadFile(Part part){
        // 获取文件名，截取后缀名
        String filename = part.getSubmittedFileName();
        filename = UUID.randomUUID().toString()+filename;
        String path= "D:/eduSource";

        // 创建文件上传的目录
        File file = new File(path);
        if(!file.exists()){
            file.mkdirs();
        }

        // 上传
        try {
            part.write(path+"/"+filename);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return filename;
    }
}
